/*字符串型*/
String.prototype.format = function(args) {//格式化字符串里的{i}占位符
    if (arguments.length>0)
    {
        var result = this;
        if (arguments.length == 1 && typeof (args) == "object")
        {
            for (var key in args)
            {
                var reg=new RegExp ("({"+key+"})","g");
                result = result.replace(reg, args[key]);
            }
        }
        else
        {
            for (var i = 0; i < arguments.length; i++)
            {
                if(arguments[i]==undefined)
                {
                    return "";
                }
                else
                {
                    var reg=new RegExp ("({["+i+"]})","g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
        return result;
    }
    else
    {
        return this;
    }
};
/*日期型*/
String.prototype.format = function (format) {
    var date = {
        "y+": this.getFullYear,
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
};
//获取几天后的时间
function GetNewDate(time)
{
    if(typeof(time)=='number')
    {
        var timestamp=new Date().valueOf();
        var afterDate=new Date(timestamp+time*24*60*60*1000);
        var result={
            year:afterDate.getFullYear(),
            month:afterDate.getMonth()+1,
            day:afterDate.getDate(),
            hour:afterDate.getHours(),
            minutes:afterDate.getMinutes(),
            secound:afterDate.getSeconds(),
            MicroSecound:afterDate.getMilliseconds()
        };
        return result;
    }
};
Date.prototype.GetNowDateTime=function(){
    var dateTmp = new Date().format("YYYY年MM月dd日hh小时mm分ss秒");
    return dateTmp;
};
/*数组函数*/
//数组去除重
Array.prototype.unique=function(){
    var arr=this;
    var tempObj={};
    var result=[];
    if(typeof(arr)=='object'||arr.length>1)
    {
        for(var i=0;i<arr.length;i++)
        {
            if(!tempObj.hasOwnProperty(arr[i]))
            {
                tempObj[arr[i]]=i;
                result.push(arr[i]);
            }
        }
        return result;
    }
    return this;
};
//整数数组冒泡排序
Array.prototype.order=function(){
    var temp=0;
    var len=this.length;
    if(len>1)
    {
        for(var i=0; i<len-1;i++)
        {
            for(var j=0;j<len-i-1;j++)
            {
                if(this[j]>this[j+1])
                {
                    temp=this[j];
                    this[j]=this[j+1];
                    this[j+1]=temp;
                }
            }
        }
    }
    return this;
};
//删除数组指定元素，如果是对象请传要删除的对象
Array.prototype.remove=function(value){
    var index = this.indexOf(value);
    if (index > -1) {
        this.splice(index, 1);
    }
    return this;
};